using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

public class Lesson13_work : MonoBehaviour
{
}

//序列化基类
public abstract class SerializeDataClassBase
{
    //获取字节数组容器
    public abstract void GetBytesNum();

    //序列化方法
    public abstract byte[] Writing();

    //序列化方法
    public void WriteShort(byte[] bytes, short value, ref int index)
    {
        int length = sizeof(short);
        BitConverter.GetBytes(value).CopyTo(bytes, index);
        index += length;
    }
    public void WriteInt(byte[] bytes, int value, ref int index)
    {
        int length = sizeof(int);
        BitConverter.GetBytes(value).CopyTo(bytes, index);
        index += length;
    }
    public void WriteString(byte[] bytes, string value, ref int index)
    {
        WriteInt(bytes, value.Length, ref index);
        Encoding.UTF8.GetBytes(value).CopyTo(bytes, index);
        index += value.Length;
    }

    public void WriteBool(byte[] bytes, bool value, ref int index)
    {
        int length = sizeof(bool);
        BitConverter.GetBytes(value).CopyTo(bytes, index);
        index += length;
    }
}
